package com.bw.zg3park2212.park

import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.view.View
import android.widget.AdapterView
import android.widget.AdapterView.OnItemSelectedListener
import android.widget.ArrayAdapter
import com.alibaba.android.arouter.facade.annotation.Route
import com.baidu.location.e.h.an
import com.blankj.utilcode.util.ToastUtils
import com.bw.base.entity.ParkAddParam
import com.bw.base.mvvm.BaseActivity
import com.bw.zg3park2212.R
import com.bw.zg3park2212.databinding.ActivityParkAddBinding

import dagger.hilt.android.AndroidEntryPoint
@Route(path = "/app/ParkAddActivity")
@AndroidEntryPoint
class ParkAddActivity : BaseActivity<ActivityParkAddBinding,ParkAddViewModle>() {
    override fun intitView() {
        var area=""
        var type=""
        var sataus=""
        binding.parkaddRemark.addTextChangedListener(object :TextWatcher{
            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {

            }

            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
                val lenght= s?.length
                binding.parkaddNum.setText(""+lenght+"/10")
                if (lenght==10){
                    binding.parkaddNum.setTextColor(Color.RED)
                }else{
                    binding.parkaddNum.setTextColor(Color.GRAY)
                }
            }

            override fun afterTextChanged(s: Editable?) {

            }
        })
        val areas= arrayListOf("A区停车场","B区停车场","C区停车场")
        val areasAdpter=ArrayAdapter(this,android.R.layout.simple_spinner_item,areas)
        areasAdpter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
        binding.edSsqy.adapter=areasAdpter
        binding.edSsqy.onItemSelectedListener=object :OnItemSelectedListener{
            override fun onItemSelected(
                parent: AdapterView<*>?,
                view: View?,
                position: Int,
                id: Long,
            ) {
                area =areas[position]
            }

            override fun onNothingSelected(parent: AdapterView<*>?) {

            }
        }
        val types= arrayListOf("标准车位","VIP车位")
        val typesAdpter=ArrayAdapter(this,android.R.layout.simple_spinner_item,types)
        typesAdpter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
        binding.edCwlx.adapter=typesAdpter
        binding.edCwlx.onItemSelectedListener=object :OnItemSelectedListener{
            override fun onItemSelected(
                parent: AdapterView<*>?,
                view: View?,
                position: Int,
                id: Long,
            ) {
                type=types[position]
            }

            override fun onNothingSelected(parent: AdapterView<*>?) {

            }
        }
        binding.parkaddRg.setOnCheckedChangeListener { group, checkedId ->
            if (checkedId==R.id.rb_kx){
                sataus="空闲"
            }else if (checkedId==R.id.rb_zy){
                sataus="已占用"
            }else{
                sataus="维护中"
            }
        }
        binding.btnAdd.setOnClickListener {
            var parkAddParam=ParkAddParam()
            parkAddParam.spaceNumber=binding.edCwbh.text.toString()
            parkAddParam.areaId=4
            parkAddParam.spaceType=type
            parkAddParam.spaceStatus=sataus
            parkAddParam.userName=binding.edSyr.text.toString()
            parkAddParam.licensePlate=binding.edCph.text.toString()
            parkAddParam.remarks=binding.parkaddRemark.text.toString()
            viewmodel.addPark(parkAddParam)
        }

    }

    override fun intitData() {
        viewmodel.parkSuccse.observe(this){
            ToastUtils.showLong("添加成功")
            finish()
        }

    }

}